console.log('foog'.replace(/(f)|(g)/g, '$1'?'g':'$2'));
